package com.rongda.deploy.operation.deploy.controller.body;

import com.rongda.deploy.operation.deploy.dto.R;
import com.rongda.deploy.operation.deploy.pojo.ServerDeploy;
import com.rongda.deploy.operation.deploy.service.DServerService;
import com.rongda.deploy.operation.deploy.service.DeployService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * Create By WeiBin on 2020/10/26 10:22
 * 服务器
 *
 * @author WB
 */
@RestController
@RequestMapping("/server")
@AllArgsConstructor
public class ServerDeployController {

    private DServerService dServerService;

    private DeployService deployService;

    @PostMapping
    public R insert(@RequestBody ServerDeploy serverDeploy) {
        if (deployService.testConnect(serverDeploy)) {
            return new R<>(this.dServerService.insert(serverDeploy));
        } else {
            return new R().error("服务器连接失败,请重试");
        }
    }

    @GetMapping
    public R list() {
        return new R<>(this.dServerService.queryAllByLimit(0, 100));
    }

    @PutMapping
    public R update(@RequestBody ServerDeploy serverDeploy) {
        if (deployService.testConnect(serverDeploy)) {
            return new R<>(this.dServerService.insert(serverDeploy));
        } else {
            return new R().error("服务器连接失败,请重试");
        }
    }


    @DeleteMapping
    public R delete(Long id) {
        return new R<>(this.dServerService.deleteById(id));
    }
}
